    <form id="rolesform" action="index.php?ctl=roles&act=save" method="POST">
		<div style="text-align:right;padding:3px 18px"><{help docid="101" type="link"}><{t}>点击查看帮助<{/t}><{/help}></div>
		<div class="division">   
				<h4><{t}>角色名称<{/t}></h4>
	   
       	<input type="text" vtype="required" name="role_name" value="<{$roles.role_name}>" class="x-input " autocomplete="off">
       </div>
     
	   <div class='division'> 
		  <h4><{t}>角色权限<{/t}></h4> 
		 <input type='hidden'  vtype='requiredcheckbox'/>  
			    <{foreach from=$workgrounds item=workground name=d }> 
                    
					   <div class="row clearfix clear" style="padding:5px;border-bottom:1px #e9e9e9 solid;">
                        <div class="span-2"><input type="checkbox" class="role_workground" value="<{$workground.workground}>"> &nbsp;&nbsp;<strong><{$workground.menu_title}></strong></div> 
						<div class="span-13" style="width:528px;"> 
						 <div class="clearfix">
                           <{foreach from=$workground.permissions item=permission key=key}>
                           <div class="span-auto"> 
							<label>
                              <input type="checkbox" class="<{$permission.role_workground}>" name="workground[]" value="<{$permission.permission}>" <{if $permission.checked}>checked=checked<{/if}>/>
                              <{$permission.menu_title}>
							</label>
                          </div>
                          <{/foreach}>  
						 </div>
						</div>
  					   </div>
					
                <{/foreach}>  
				   
			
					<div class="row clearfix clear" style="padding:5px;"> 
						      <div class="span-2"><strong><{t}>控制面板<{/t}></strong></div>
							  <div class="span-13" style="width:528px;">
								<div class="clearfix">
						<{foreach from=$adminpanels item=adminpanel key=key}>
		                        <div class="span-auto">
									<label>
		                        <input  type="checkbox" name="workground[]" value="<{$adminpanel.permission}>" <{if $adminpanel.checked}>checked=checked<{/if}>/>
								<{$adminpanel.menu_title}>
									</label>
                                 </div>
		                        <{/foreach}>  
								</div>
							  </div>
						</div>
			 
					<div class="row clearfix clear" style="padding:5px;"> 
						      <div class="span-2"><strong><{t}>桌面挂件<{/t}></strong></div>
							  <div class="span-13" style="width:528px;">
								<div class="clearfix">
						<{foreach from=$widgets item=widget key=key}>
		                        <div class="span-auto">
									<label>
		                        <input  type="checkbox" name="workground[]" value="<{$widget.addon}>" <{if $widget.checked}>checked=checked<{/if}>/>
								<{if $widget.checked}><font color="red"><{$widget.menu_title}></font> <{/if}>
									</label>
                                 </div>
		                        <{/foreach}>  
								</div>
							  </div>
						</div>
			 
				<{if $others}>
				   <div class="row clearfix clear" style="padding:5px;"> 
						      <div class="span-2"><strong><{t}>其他<{/t}></strong></div>
							  <div class="span-13" style="width:528px;">
								<div class="clearfix">
						<{foreach from=$others item=other key=key}>
		                        <div class="span-auto">
									<label>
		                        <input  type="checkbox" name="workground[]" value="<{$other.permission}>" <{if $other.checked}>checked=checked<{/if}>/>
								<{$other.menu_title}>
									</label>
                                 </div>
		                        <{/foreach}>  
								</div>
							  </div>
						</div>
				<{/if}>

	   </div>
    </form>


<{area inject=".mainFoot"}>
		<div class="table-action">
                   <{button label=$___desktop="确定"|t:'desktop' id="rolesform-submit" class="btn-primary"}>
	   </div>
<{/area}>
<script>
function nameCheck(input){
	id = input.value;
	role_id = $('roleID').value;
    if((input.checked)){
        new Request.HTML({url:'index.php?app=desktop&ctl=roles&act=get_permission',method:'post',
		update:$(input).getNext(),data:'role_id='+role_id+'&name='+encodeURIComponent(input.value=input.value.trim())}).send();
    $('workground'+id).setStyle('display','block');    
    }
    else{
        $('workground'+id).setStyle('display','none').empty();;
    }
  
}

</script>
<script>
(function(){
    var _form = $('rolesform');
    var btn =$('rolesform-submit');
    var finder = finderGroup['<{$env.get.finder_id}>'];
    
    _form.store('target',{
       onComplete:function(){
	  },
	  onSuccess:function(response){
		var hash_res_obj = JSON.decode(response);
		if (hash_res_obj.success != undefined && hash_res_obj.success != ""){
		  try{
			var _dialogIns = btn.getParent('.dialog').retrieve('instance');
		  }catch(e){}

		  if(_dialogIns){
			_dialogIns.close();
			finder.refresh.delay(400,finder);

		  }
		}
	  }
        
    });

        btn.addEvent('click',function(){
        
            _form.fireEvent('submit',{stop:$empty});
            
        
        
        });
    
})();
if ($$('.role_workground'))
{
    $$('.role_workground').addEvent('click',function(e){
        var role_menu = this.value;
        var checked = this.checked;
        var _this=this;
        $$('.'+role_menu+'').each(function(role){
            role.set('checked',checked);
        }
        );
        $$('.'+role_menu+'').addEvent('click',function(item){
            if (checked == true)
            {
              checked = false;
               _this.set('checked',false);
            }

        });

    });
}    

</script>
